package com.czk.suspend;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.runtime.ProcessInstanceQuery;

/**
 * 单个流程实例的挂起
 * @Author ChenZhangKun
 * @Date 2020/9/11 9:28
 */
public class SingleInstanceSuspend {
    public static void main(String[] args) {
        // 得到引擎
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 得到流程实例对象
        RuntimeService runtimeService = processEngine.getRuntimeService();
        // 查询流程实例对象
        ProcessInstanceQuery processInstanceQuery = runtimeService.createProcessInstanceQuery();
        // 封装查询对象
        ProcessInstance holiday = processInstanceQuery.processInstanceId("2501").singleResult();
        // 拿到id
        String id = holiday.getId();
        // 拿到名称
        String name = holiday.getName();
        // 是否挂起
        boolean suspended = holiday.isSuspended();
        if (suspended){
            // 激活
            runtimeService.activateProcessInstanceById(id);
            System.out.println(name+"被激活");
        }else {
            // 挂起
            runtimeService.suspendProcessInstanceById(id);
            System.out.println(name+"被挂起");
        }
    }
}
